<?xml version="1.0" encoding="UTF-8"?>
<?altova_samplexml la_principessa.xml?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:asp="remove" xmlns:ctl="remove" xmlns:tinymce="remove" xmlns:ptl="remove">
	<xsl:output method="xhtml" omit-xml-declaration="yes" />
	<xsl:template match="/">
		<xsl:if test="//root/items/item/name/text()">
        	<xsl:call-template name="TrySons">
            	<xsl:with-param name="sons" select="//root/items"></xsl:with-param>
            </xsl:call-template>
        </xsl:if>
	</xsl:template>
    
    <xsl:template name="TrySons">
    	<xsl:param name="sons"></xsl:param>
            <xsl:for-each select="$sons/item">
            	<xsl:choose>
                	<xsl:when test="link='#'">
                    	<h3 class="menuDad atStart"><xsl:value-of select="name"></xsl:value-of></h3>
                        <div class="atStart"><ul class="blocchi">
                        <xsl:call-template name="CallSons">
                            <xsl:with-param name="sons" select="./items"></xsl:with-param>
                            <xsl:with-param name="parent" select="name"></xsl:with-param>                            
                            <xsl:with-param name="first" select="1"></xsl:with-param>                            
                            
                        </xsl:call-template>
                        </ul></div>
                    </xsl:when>
                </xsl:choose>
          </xsl:for-each>
    </xsl:template>
    
    
        <xsl:template name="CallSons">
    	<xsl:param name="sons"></xsl:param>
    	<xsl:param name="parent"></xsl:param>  
    	<xsl:param name="first"></xsl:param>                
            <xsl:for-each select="$sons/item">
            	<xsl:choose>
                	<xsl:when test="link='#'">
                        <xsl:call-template name="CallSons">
                            <xsl:with-param name="sons" select="./items"></xsl:with-param>
                            <xsl:with-param name="parent" select="name"></xsl:with-param>
							<xsl:with-param name="first">0</xsl:with-param>                            
                        </xsl:call-template>
                    </xsl:when>
                    <xsl:otherwise>
                    	<li>         
                        <xsl:variable name="linker">
                        	<xsl:choose>
                            	<xsl:when test="contains(link,'?')">&amp;idc=<xsl:value-of select="idcomp"></xsl:value-of>&amp;idi=<xsl:value-of select="idmod"></xsl:value-of></xsl:when>
                                <xsl:otherwise>?idc=<xsl:value-of select="idcomp"></xsl:value-of>&amp;idi=<xsl:value-of select="idmod"></xsl:value-of></xsl:otherwise>
                            </xsl:choose>
                        </xsl:variable>       
                        <a href="{link}{$linker}" title="{name}">   
                        <xsl:if test="img/text()">
                            <xsl:choose>
                            <xsl:when test="idcomp='-1'">
                                <img src="/administration/template/admimg/{img}" alt="{name}" style="border:0px;" /><br/>
                            </xsl:when>
                            <xsl:otherwise>
                                <img src="/controls/{../../componentpath}/{img}" alt="{name}" style="border:0px;" /><br/>
                            </xsl:otherwise>
                            </xsl:choose>
                        </xsl:if>
                        <xsl:value-of select="name"></xsl:value-of>
                        <span><xsl:if test="$first='0'">
                        (<xsl:value-of select="$parent"></xsl:value-of>)
                        </xsl:if></span>                        
                        </a>

                        </li>
                    </xsl:otherwise>
                </xsl:choose>
          </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>